<?php
require_once ("navigationview.php");
class LoginView {
	private $pass = "passw";
	private $users = "users";
	private $remeberme = "remeber";
	private $CookieName = "Cookiename";
	private $Cookiepass = "Cookiepass";

	public function DoLoginBox() {
		//debug_print_backtrace();
		//inloggning form-tagg...
		$NavigationView = new NavigationView();
		return "<div id='registration'>
		<h2>Logga in</h2>
		
 <form id='RegisterUserForm' action='' method='Get'>
 	<fieldset>
		<p>
			<label for='name'>Användare/Namn</label>
			<input type='text' size='30' name='$this->users' id='name' class='text' value='' />
		</p>
		<p>
 			<label for='tel'>Lösenord</label>
 			<input  type='password' size='30' name='$this->pass' class='text' id='tel' value='' />
 		</p>
 			<input type='submit' name='submit' id='submit' value='Logga in'/>
			<form name='login' id='registerNew' method='Get' action='" . $NavigationView -> GetRegisterIndex() . "'>
			<input type='submit' name='" . NavigationView::RegisterIndex . "' id='submit' value='Registera dig'/>
		</form>
	</fieldset>
 </form>
 </div>";


	}





	public function GoToEventApp() {
		$NavigationView = new NavigationView();
		return "
					<div class='register'>
						<form name='login' id='login' method='Post' action='" . NavigationView::GetUrlToEventIndex() . "'>
							<input type='submit' name='GoToEvent' id='submit' value='Evenemang'/>
						</form>
					</div>";

	}

	public function DoLogoutBox() {
		//loggar ut button...
		return "<form action='index.php' <p><input type='submit' name='LogOut' id='submit' value='Logga ut'/></p> </form>";
	}

	//kolla användarnamn...
	public function GetUserName() {
		if (isset($_GET[$this -> users])) {
			return $_GET[$this -> users];
		}
		if (isset($_COOKIE[$this -> CookieName])) {
			Return $_COOKIE[$this -> CookieName];
		}
		return FALSE;
	}

	//kolla lösenord...
	public function GetPassword() {
		if (isset($_GET[$this -> pass])) {
			return $_GET[$this -> pass];
		}
		if (isset($_COOKIE[$this -> Cookiepass])) {
			return $_COOKIE[$this -> Cookiepass];
		}
		return FALSE;
	}

	// provar att logga in...
	public function TriedToLogIn() {
		if (isset($_GET["submit"])) {

			Return True;
		}
		if (isset($_COOKIE[$this -> CookieName])) {

			return true;

		}

		return FALSE;

	}

	public function TriedToGoToEvent() {
		if (isset($_POST["GoToEvent"])) {

			Return True;
		}

		return FALSE;

	}

	//provar att logga ut...
	public function TriedToLogOut() {
		if (isset($_GET["LogOut"])) {
			$this -> DeletemyCookie();
			Return True;
		}
		return FALSE;

	}

	public function RememberMe() {
		if (isset($_GET[$this -> remeberme])) {
			setcookie($this -> CookieName, $this -> GetUserName(), time() + 60 * 60 * 24);
			setcookie($this -> Cookiepass, $this -> GetPassword(), time() + 60 * 60 * 24);
			Return True;
		}
		return FALSE;
	}

	public function getLoggedInOkfeeedback() {
		$NavigationView = new NavigationView();
		if (isset($_GET[$this -> remeberme])) {
			$this -> RememberMe();
		}
		if (isset($_GET["submit"])) {
			$Stringer = "Du är inloggad</br>";
			$Stringer .= "</br> Välkommen " . $this -> GetUserName();

			Return $Stringer;
		} else {

			$Stringer = "Du är inloggad via cookies</br>";
			$Stringer .= "</br> Välkommen " . $this -> GetUserName();

			Return $Stringer;
		}

		return "";
	}

	public function DeletemyCookie() {

		setcookie($this -> CookieName, "", time() - 60 * 60 * 24);
		setcookie($this -> Cookiepass, "", time() - 60 * 60 * 24);
		unset($_COOKIE[$this -> CookieName]);
		unset($_COOKIE[$this -> Cookiepass]);
		Return True;
	}

	public function stringoutlog() {

		$Stringer = "Du är utloggad</br>";

		Return $Stringer;

	}

	public function welback() {

		$Stringer = "Välkommen tillbaka</br>" . $this -> GetUserName();
		$Stringer .= "</br>";

		return $Stringer;

	}

	public function wrongstring() {

		$Stringer = "Fel användarnamn eller lösenord";

		return $Stringer;

	}

}
